//
//  FavoriteCell.m
//  体育商城
//
//  Created by  on 2022/9/24.
//

#import "FavoriteCell.h"
@interface FavoriteCell()
@property (strong, nonatomic) IBOutlet UIButton *selectBtn;
@property (strong, nonatomic) IBOutlet UIButton *nameBtn;
@property (strong, nonatomic) IBOutlet UIImageView *goodImg;
@property (strong, nonatomic) IBOutlet UILabel *goodTitle;
@property (strong, nonatomic) IBOutlet UILabel *gooddetail;
@property (strong, nonatomic) IBOutlet UILabel *goodMoney;
@property (strong, nonatomic) IBOutlet UITextField *input;
@end

@implementation FavoriteCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
- (IBAction)actionForBtn:(UIButton *)sender {
    if (sender.tag == 201) {///选中状态
        sender.selected = !sender.selected;
        if (self.block) {
            self.block(sender);
        }
    }else if (sender.tag == 202){///商店
       
    }else if (sender.tag == 203){///减
        int num = [self.input.text intValue];
        num = num <= 1 ? num : num-1;
        self.input.text = [NSString stringWithFormat:@"%d",num];
        self.model.payNum = self.input.text;
        if (self.block) {
            self.block(sender);
        }
    }else if (sender.tag == 204){///加
        int num = [self.input.text intValue];
        num += 1;
        self.input.text = [NSString stringWithFormat:@"%d",num];
        self.model.payNum = self.input.text;
        if (self.block) {
            self.block(sender);
        }
    }
    
}
- (void)setModel:(Goods*)model{
    _model = model;
    self.selectBtn.selected = model.select;
    self.input.text = model.payNum;
    self.goodImg.image = nil;
    self.goodTitle.text = [NSString stringWithFormat:@"%@ %@",model.brandName,model.shortDescription];
    self.goodMoney.text = [NSString stringWithFormat:LS(@"¥:%@"),model.price];
    self.gooddetail.text = [NSString stringWithFormat:LS(@"月销量%d万+"),[model.productReference intValue] / 10000];
    [self.nameBtn setTitle:model.name forState:UIControlStateNormal];
    self.task = [UIImage imageWithURL:model.mainImage block:^(UIImage * _Nonnull image) {
        self.goodImg.image = image;
    }];
}
@end
